home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / doc / xdice.pro < prev   
Text File  |  1997-07-08  |  2KB  |  89 lines

  1. ; $Id: xdice.pro,v 1.1 1996/10/01 22:03:16 doug Exp $
  2.  
  3. ; Copyright (c) 1993, Research Systems, Inc.  All rights reserved.
  4. ;       Unauthorized reproduction prohibited.
  5. ;+
  6. ; NAME:
  7. ;       XDICE
  8. ;
  9. ; PURPOSE:
  10. ;    The primary purpose of this routine is to serve as an example for
  11. ;    the Widgets chapter of the IDL User's Guide. It uses the CW_DICE
  12. ;    compound widget (also written as an example) to present a pair
  13. ;    of dice.
  14. ;
  15. ; CATEGORY:
  16. ;       Widgets
  17. ;
  18. ; CALLING SEQUENCE:
  19. ;       XDICE
  20. ;
  21. ; INPUTS:
  22. ;       No explicit inputs.
  23. ;
  24. ; KEYWORD PARAMETERS:
  25. ;       GROUP - Group leader, as passed to XMANAGER.
  26. ;
  27. ; OUTPUTS:
  28. ;       None.
  29. ;
  30. ; PROCEDURE:
  31. ;    Two dice are presented, along with "Done" and "Roll" buttons.
  32. ;    Pressing either dice rolls that dice. pressing the Roll
  33. ;    button rolls both dice.
  34. ;
  35. ;    A label widget at the bottom displays the current dice values.
  36. ;    Press "Done" to kill the application.
  37. ;
  38. ; MODIFICATION HISTORY:
  39. ;    24 October 1993, AB, RSI
  40. ;-
  41.  
  42. pro xdice_event, ev
  43.  
  44.   ; Recover the state
  45.   WIDGET_CONTROL, ev.top, GET_UVALUE=state, /NO_COPY
  46.  
  47.   if (ev.id eq state.bgroup) then begin
  48.     if (ev.value eq 0) then begin
  49.       WIDGET_CONTROL, /DESTROY, ev.top
  50.       return
  51.     endif else begin
  52.       WIDGET_CONTROL, state.d1, SET_VALUE=-1
  53.       WIDGET_CONTROL, state.d2, SET_VALUE=-1
  54.     endelse
  55.   endif
  56.  
  57.   ; Update Label
  58.   WIDGET_CONTROL, state.d1, get_value=d1v
  59.   WIDGET_CONTROL, state.d2, get_value=d2v
  60.   WIDGET_CONTROL, state.label, $
  61.     set_value=string(format='("Current Value: ", I1, ", ", I1)', d1v, d2v)
  62.  
  63.   ; Restore the state
  64.   WIDGET_CONTROL, ev.top, SET_UVALUE=state, /NO_COPY
  65.  
  66. end
  67.  
  68.  
  69. pro xdice, GROUP=group
  70.  
  71.   base = widget_base(/COLUMN, title='Pair O'' Dice')
  72.   bgroup=cw_bgroup(base, ['Done', 'Roll'], /ROW, SPACE=50)
  73.   dice=widget_base(base, /ROW, XPAD=20)
  74.   d1 = cw_dice(dice)
  75.   d2 = cw_dice(dice)
  76.   WIDGET_CONTROL, d1, get_value=d1v
  77.   WIDGET_CONTROL, d2, get_value=d2v
  78.   label=WIDGET_LABEL(base, $
  79.             value=string(format='("Current Value: ", I1, ", ", I1)', d1v, d2v))
  80.  
  81.   ; Keep useful information in UVALUE of top-level base.
  82.   state = { bgroup:bgroup, d1:d1, d2:d2, label:label }
  83.   ; Use the UVALUE of the top-level base to hold both Dice IDs.
  84.   widget_control, base, set_uvalue=state, /NO_COPY, /REAL
  85.  
  86.   XMANAGER,'XDICE', base, GROUP=group
  87. end
  88.  
  89.